<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="企业名称">
              <j-input placeholder="请输入企业名称" v-model="queryParam.enterpriseName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="订单日期">
              <!--              <a-input placeholder="请输入订单日期" v-model="queryParam.createTime"></a-input>-->
              <a-date-picker v-model="queryParam.createTime" format='YYYY-MM-DD HH:mm:ss' showTime @change="stringify"
                             style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <!-- <a-form-item label="进店日期">
              <j-input placeholder="请输入进店日期" v-model="queryParam.salesName"></j-input>
            </a-form-item>-->
            <a-form-item label="销售顾问">
              <j-input placeholder="请输入销售顾问" v-model="queryParam.salesName"></j-input>
            </a-form-item>
          </a-col>

          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="客户姓名">
                <j-input placeholder="请输入客户姓名" v-model="queryParam.ownerName"></j-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="客户电话">
                <j-input placeholder="请输入客户电话" v-model="queryParam.salesPhone"></j-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <!-- <a-form-item label="进店日期">
                <j-input placeholder="请输入进店日期" v-model="queryParam.salesName"></j-input>
              </a-form-item>-->
              <a-form-item label="状态">
                <a-select v-model="queryParam.linkStatus" placeholder="请选择状态">
                  <a-select-option value="0">
                    未确认
                  </a-select-option>
                  <a-select-option value="1">
                    已确认
                  </a-select-option>
                  <a-select-option value="2">
                    异议
                  </a-select-option>
                  <a-select-option value="3">
                    异议待确认
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>

          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>

      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--      <a-button @click="handleAdd" type="primary" icon="plus">客户进店登记</a-button>-->
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('cxm-订单记录信息')">导出</a-button>-->
      <!--      <a-upload-->
      <!--        name="file"-->
      <!--        :showUploadList="false"-->
      <!--        :multiple="false"-->
      <!--        :headers="tokenHeader"-->
      <!--        :action="importExcelUrl"-->
      <!--        @change="handleImportExcel"-->
      <!--      >-->
      <!--        <a-button type="primary" icon="import">导入</a-button>-->
      <!--      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        :rowKey="(record,index)=> index"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
        :scroll="{ x: 1250 }"
      >
        <span slot="action" slot-scope="text, record">
          <a-button type="primary" @click="showModal(record)">详细操作</a-button>
          <!--          <a-button @click="showModal(record)">作废</a-button>-->
          <a-modal v-model="visible2" title="作废提示" @ok="getInfo(recordInfo)">
            <p>是否对该条记录进行作废？作废后将无法恢复！</p>
          </a-modal>
        </span>

        <span
          slot="filterDepositAttribute"
          slot-scope="powerType"
        >{{ powerType | filterDepositAttribute(powerType) }}</span>
        <span
          slot="statusFilter"
          slot-scope="powerType"
        >{{ powerType | statusFilter(powerType) }}</span>
      </a-table>
      <check-detail-modal ref="CheckDetailModal"></check-detail-modal>
    </div>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <cxmOrderManager-modal ref="modalForm" @ok="modalFormOk"></cxmOrderManager-modal> -->
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JInput from '@comp/jeecg/JInput'
import moment from 'moment'
import { USER_INFO } from '@/store/mutation-types'
import Vue from 'vue'
import { getAction, httpAction } from '@api/manage'
import CheckDetailModal from './CheckDetailModal'

export default {
  name: 'signCheck',
  mixins: [JeecgListMixin],
  components: {
    JInput,
    moment,
    CheckDetailModal
  },
  data() {
    return {
      description: 'cxm-订单管理页面',
      visible: false,
      visible2: false,
      // 表头
      loading: '',
      columns: [
        {
          title: '档案号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '企业名称',
          align: 'center',
          width: 350,
          dataIndex: 'enterpriseName'
        },
        {
          title: '客户姓名',
          align: 'center',
          width: 160,
          dataIndex: 'ownerName'
        },
        {
          title: '客户电话',
          align: 'center',
          width: 200,
          dataIndex: 'ownerPhone'
        },
        {
          title: '订单日期',
          align: 'center',
          width: 200,
          dataIndex: 'createTime'
        },
        {
          title: '网签环节',
          align: 'center',
          width: 160,
          dataIndex: 'links',
          scopedSlots: {
            customRender: 'filterDepositAttribute'
          }
        },
        {
          title: '网签状态',
          align: 'center',
          width: 160,
          dataIndex: 'linkStatus',
          scopedSlots: {
            customRender: 'statusFilter'
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 180,
          scopedSlots: {
            customRender: 'action'
          }
        }
      ],

      url: {
        list: '/cxm/allCxmOrder/list',
        delete: '/sale/cxmSaleIntention/delete',
        deleteBatch: '/sale/cxmSaleIntention/deleteBatch',
        exportXlsUrl: 'sale/cxmSaleIntentionexportXls',
        importExcelUrl: 'sale/cxmSaleIntentionimportExcel'
      },
      recordInfo: {}
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${process.env.VUE_APP_BASE_API}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    stringify(e) {
      if (e) {
        this.queryParam.createTime = this.queryParam.createTime.format('YYinYY-MM-DD HH:mm:ss')
      }
    },
    showModal(record) {
      this.$refs.CheckDetailModal.edit(record)
      // this.visible2 = true
      // this.recordInfo = record
    },
    getInfo(recordInfo) {
      console.log(recordInfo)
      const that = this
      /* this.$refs.cxmOrderManagerInfoModal.showDrawer(record) */
      let url = this.url.delete + '?id=' + recordInfo.id
      httpAction(url, {}, 'post').then((res) => {
        this.visible2 = false
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
          that.loadData()
        } else {
          that.$message.warning(res.message)
          that.loadData()
        }
      })
        .finally(() => {
          that.confirmLoading = false
          that.loadData()
        })
    }
  },
  filters: {
    filterTime(time) {
      return moment(time).format('YYYY-MM-DD')
    },
    filterDepositAttribute(depositAttribute) {
      //0-订单；1-合同；2-交付
      switch (depositAttribute) {
        case '0':
          return '订单'
          break
        case '1':
          return '合同'
          break
        case '2':
          return '交付'
          break
      }
    },
    statusFilter(depositAttribute) {
      //0-未确定；1-已确认；2-异议；3-异议待确认
      switch (depositAttribute) {
        case '0':
          return '未确认'
          break
        case '1':
          return '已确认'
          break
        case '2':
          return '异议'
          break
        case '3':
          return '异议待确认'
          break
      }
    }
  }
}
</script>
<style scoped>
</style>
